﻿Partial Public Class SocietyExplorer

    Public Overridable Sub TreeActionOptionListLoad()
        'ACT_00195 est utiliser par default sur les explorer
        Me.MetaControlTreeListActionOptionList.Add(New ActionOption("SocietyRoot", "ACT_00204", "Card view", AddressOf Society_GridLayout, True, True, 0))

    End Sub

    Private Sub MetaControlActionOptionListLoad()
        Dim action As CommonExt.Base.ActionOption
        action = New ActionOption("Site", "ACT_00207", "Create default Site", AddressOf Society_DefaultSite, True, True, "Society") 'scope on Site

        MetaControlTreeListActionOptionList.Add(action)

    End Sub


    Public Overridable Sub ProcessCurrentMasterRecord(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs)
        Throw New NotImplementedException
    End Sub
    Public Overridable Sub ValidateMasterRow(sender As Object, e As Views.Base.ValidateRowEventArgs)
        Throw New NotImplementedException
    End Sub

    Public Overridable Sub ValidateDetailRow(sender As Object, e As Views.Base.ValidateRowEventArgs)
        Throw New NotImplementedException
    End Sub

    Public Overridable Sub InitNewMasterRow(sender As Object, e As InitNewRowEventArgs)
        Dim view As GridView = CType(sender, GridView)
        Dim row As DataRow = view.GetFocusedDataRow()
        Using Society As SystemBoxSDK.PL.CoreSDK.Society_PL = New SystemBoxSDK.PL.CoreSDK.Society_PL()
            Society.NewRecord(row)
        End Using

    End Sub

    Public Overridable Sub InitNewDetailRow(sender As Object, e As InitNewRowEventArgs)
        Throw New NotImplementedException
    End Sub

    Public Overridable Sub ProcessCurrentDetailRecord(sender As Object, e As Views.Base.ValidateRowEventArgs, index As Integer)
        Throw New NotImplementedException
    End Sub

    Public Overridable Sub DetailCellValueChanged(sender As Object, e As Views.Base.CellValueChangedEventArgs)
        Throw New NotImplementedException
    End Sub

    Public Overridable Sub MasterRowClick(sender As Object, e As RowClickEventArgs)
        Throw New NotImplementedException
    End Sub

    Public Overridable Sub DetailRowClick(sender As Object, e As RowClickEventArgs)
        Throw New NotImplementedException
    End Sub

    Public Overridable Sub DetailCustomRowCellEditForEditing(sender As Object, e As CustomRowCellEditEventArgs)
        Throw New NotImplementedException
    End Sub

    Public Overridable Sub SocietyDetail_CustomRowCellEditForEditing(ByVal sender As Object, ByVal e As CustomRowCellEditEventArgs)
        Dim aView As GridView = DirectCast(sender, GridView)
        Dim aRTEdit As RepositoryItemButtonRichTextEditExt
        Dim aLov As New RepositoryItemGridLookUpEdit()

        Dim aRow As DataRow = aView.GetFocusedDataRow()

        If aView.Tag.ToString = "SocietyActivity" Then
            If Not IsNothing(aView.Columns("ProjectDocument")) Then
                If e.Column.FieldName = "ProjectDocument" Then
                    aRTEdit = New RepositoryItemButtonRichTextEditExt

                    If e.CellValue Is Nothing Then
                        aRTEdit.Text = String.Empty
                    Else
                        aRTEdit.Text = e.CellValue.ToString
                    End If

                    aView.GridControl.RepositoryItems.Add(aRTEdit)
                    e.RepositoryItem = aRTEdit
                End If
            End If
        End If


    End Sub

    Public Overridable Sub InitNewLayoutRow(sender As Object, e As InitNewRowEventArgs)
        Dim LayoutView As LayoutView = CType(sender, LayoutView)
        Dim row As DataRow = LayoutView.GetFocusedDataRow()
        Using Society As SystemBoxSDK.PL.CoreSDK.Society_PL = New SystemBoxSDK.PL.CoreSDK.Society_PL()
            Society.NewRecord(row)
        End Using
        row("Inactive") = 0
    End Sub

    Private Sub Society_DefaultSite(ByVal sender As Object, ByVal e As EventArgs)
        Dim sqlcmd As System.Data.SqlClient.SqlCommand = Nothing
        Try
            'RUN on SystemBox_Master
            sqlcmd = MetaQuery.GetSPCmdByMetaName("bsp_Society_PL_SaveToSite")

            sqlcmd.Parameters.Clear()
            sqlcmd.Parameters.AddWithValue("@SocietyID", DirectCast(NodeDataRow(Me.KeyFieldName), Guid))
            sqlcmd.ExecuteReader(CommandBehavior.CloseConnection)

            MessageWindow.ShowMessage("Update to Site completed with success", MsgBoxStyle.Information)
        Catch sqlex As System.Data.SqlClient.SqlException
            Throw sqlex
        Catch ex As Exception
            Throw ex
        Finally
            If sqlcmd IsNot Nothing Then
                sqlcmd.Connection.Close()
                sqlcmd.Dispose()
            End If
        End Try


    End Sub

End Class
